package com.aerozhonghuan.archive.controller;

import com.aerozhonghuan.archive.dto.VerificationResult;
import com.aerozhonghuan.archive.service.DataConsistencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/data-consistency")
public class DataConsistencyController {

    private final DataConsistencyService dataConsistencyService;

    @Autowired
    public DataConsistencyController(DataConsistencyService dataConsistencyService) {
        this.dataConsistencyService = dataConsistencyService;
    }

    /**
     * 校验记录数一致性
     */
    @GetMapping("/verifyCount")
    public List<VerificationResult> verifyCount(
            @RequestParam("currentTime")
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date currentTime) {
        return dataConsistencyService.verifyCountConsistency(currentTime);
    }

    /**
     * 进行随机抽样的 MD5 校验
     */
    @GetMapping("/verifyMd5")
    public List<VerificationResult> verifyMd5(
            @RequestParam("currentTime")
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date currentTime,
            @RequestParam(value = "sampleCount", defaultValue = "10") int sampleCount) {
        return dataConsistencyService.verifyMd5Consistency(currentTime, sampleCount);
    }
}
